<?php
 
accessPage(5);
my_component_load('testing' , false);
my_component_load('paging' , false);
my_component_load('pelamar');
$task = isset($_GET['task']) ? $_GET['task'] : ""; 
$id = isset( $_GET['id'] ) ? $_GET['id']:  0;
$pelamar_id = isset( $_GET['pelamar_id'] ) ? $_GET['pelamar_id']:  0;
$pel_org_id = isset( $_GET['pel_org_id'] ) ? $_GET['pel_org_id']:  0;
$pelamar_ahli_id = isset( $_GET['pelamar_ahli_id'] ) ? $_GET['pelamar_ahli_id']:  0;
$pelamar_seleksi_id  = isset( $_GET['pelamar_seleksi_id'] ) ? $_GET['pelamar_seleksi_id']:  0;
$modulname = "Personalia _BN_ Penempatan _BN_ Calon Karyawan _BN_ Pelamar";
if($_SERVER['REQUEST_METHOD'] == "POST" ):
	switch($task){
		case   "edit" :
			$validatepost = form_validate($id);
			if($validatepost){
				$pagename= ($id > '0' ) ?  "Perubahan Data" : "Tambah Data";
				$pagename .= " pelamar kerja";			
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .= form_create($id);

			}else{
				form_submit($id);
			 }
			break; 	
		case   "edit_ptk_page" :
			$validatepost = edit_ptk_validate($pelamar_id);
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .= edit_ptk($pelamar_id);
				generate_my_web($content,"","plain.php");
				exit; 
			}else{
				edit_ptk_submit($pelamar_id);
				$content =  "Updated";
				generate_my_web($content,"","plain.php");
				exit;
			 }
			break; 		
		case   "create_organisasi_page" : 
			create_organisasi_pelamar_submit($pelamar_id );
			$content ="Updated";
			generate_my_web($content,"","plain.php"); 
			exit;
		break;	
		case   "create_keahlian_page" : 
			create_keahlian_submit($pelamar_id );
			$content ="Updated";
			generate_my_web($content,"","plain.php"); 
			exit;
		break;
		case   "setuji_page" :
			pelamar_ujian_submit($pelamar_id ,$pelamar_seleksi_id);
			$content ="Updated";
			generate_my_web($content,"","plain.php");
			exit;
		break;
		default:
			set_pelamar_test($_POST['a']); 
		break;
	}

else: 	
	if($task == "edit"){
		$pagename= ($id > '0' ) ?  "Perubahan Data" : "Tambah Data";
		$pagename .= " pelamar kerja";
		$content = form_create($id);
	}elseif($task == "create_organisasi_page"){
		$content =create_organisasi_pelamar($pelamar_id);
		generate_my_web($content,"","plain.php");
		exit; 
	}elseif($task == "create_keahlian"){
		$pagename= "Tambah data keahlian" ; 
		facebox_page('index.php?com='.$_GET['com'].'&task=create_keahlian_page&pelamar_id='.$pelamar_id , $pagename , 200	); 
	}elseif($task == "create_keahlian_page"){
		$content =create_keahlian($pelamar_id);
		generate_my_web($content,"","plain.php");
		exit;
	}elseif($task == "create_organisasi"){
		$pagename= "Tambah data pengalaman organisasi" ; 
		facebox_page('index.php?com='.$_GET['com'].'&task=create_organisasi_page&pelamar_id='.$pelamar_id , $pagename , 200	); 		
	}elseif($task == "delete_setuji"){
		my_query("DELETE FROM pelamar_seleksi WHERE pelamar_seleksi_id ={$id} ");
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == "delete"){
		my_query("DELETE FROM pelamar WHERE pelamar_id = {$id} ");
		my_query("DELETE FROM pelamar_alamat WHERE pelamar_id = {$id} ");
		my_query("DELETE FROM pelamar_seleksi WHERE pelamar_id = {$id} ");
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == "delete_ahli"){
		my_query("DELETE FROM pelamar_keahlian WHERE pelamar_ahli_id = {$pelamar_ahli_id}");
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == "delete_org"){
		my_query("DELETE FROM pelamar_organisasi WHERE pelamar_org_id = {$pel_org_id}");
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == "infopelamar"){
		
		load_facebox_script();
		$pelamar = my_get_data_by_id('pelamar','pelamar_id',$pelamar_id);
		$pagename = "Detail data ".$pelamar['nama'];
		$content = detail_pelamar($pelamar); 
	}elseif($task == "detail"){
		$pagename = "Detail data pelamar kerja";
		load_facebox_script();
		$content = pelamar_ujian_progress($id);
	}elseif($task == "setuji_page"){ 
		$content =pelamar_ujian($pelamar_id,$pelamar_seleksi_id);
		generate_my_web($content,"","plain.php");
		exit;
	}elseif($task == "diterima"){
		seleksi_pelamar_diterima($pelamar_id);
		my_direct('index.php?com='.$_GET['com']);
	}elseif($task == "seleksi"){
		$pagename = "Penempatan _BN_ Calon Karyawan _BN_ Seleksi Pelamar";
		load_facebox_script();
		$content = report_calon_karyawan_seleksi();
	}elseif($task == "setuji"){
		facebox_page('index.php?com=pelamar&task=setuji_page&pelamar_seleksi_id='.$pelamar_seleksi_id.'&pelamar_id='.$pelamar_id , "Jadwal ujian pelamar", 220	); 
	}elseif($task == "edit_ptk"){
		facebox_page('index.php?com=pelamar&task=edit_ptk_page&pelamar_id='.$pelamar_id , "PTK", 220	); 
	}elseif($task == "edit_ptk_page"){ 
		$content =edit_ptk($pelamar_id);
		generate_my_web($content,"","plain.php");
		exit;
	}elseif($task == "plaincetak"){
		@ob_end_clean(); 
		echo'<pre>';
		echo print_plain();
		exit;
	}elseif($task == "excel"){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=penilaian.xls");
		echo excel_report();
		exit;			
	}else{
		$pagename = $modulname;
		load_facebox_script();
		$content = report_calon_karyawan();
	}
endif; 
generate_my_web($content, $pagename  );
?>